package com.ohs.controller.before;

import com.ohs.pojo.Product;
import com.ohs.service.ProService;
import com.ohs.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/pro")
public class ProController {
    @Autowired
    private ProService proService;

    //从首页去到花瓶列表页面
    @GetMapping("/vaseProList")
    public String vaseProList(Model model) {
        String s = proService.findVaseProList(model);
        return s;
    }

    //查询商品的各种信息到详情页面
    @GetMapping("/proDetail")
    public String proDetail(Model model, Integer proId) {
        String s = proService.findProDetail(model, proId);
        return s;
    }

    //去到全部商品
    @GetMapping("/allPro")
    public String toAllPro(Model model, HttpSession session, String param) {
        String view = proService.findAllPro(model, session, param);
        return view;
    }

    //添加购物车
    @PostMapping("/addShopCar")
    @ResponseBody
    public ResponseResult addShopCar(Product pro, Integer quantity, HttpSession session) {
        return proService.addShopCar(pro, quantity, session);
    }

    //根据商品名模糊搜索
    @PostMapping("/search")
    public String search(String searchContent, Model model) {
        List<Product> proList = proService.findProByName(searchContent, model);
        model.addAttribute("proList", proList);
        return "before/searchResult";
    }

    //创意家居页面
    @GetMapping("/ideaPro")
    public String ideaPro(Model model, HttpSession session, String param) {
        String view = proService.findIdeaPro(model, session, param);
        return view;
    }

    //布艺软饰页面
    @GetMapping("/softDecoration")
    public String softDecoration(Model model, HttpSession session, String param) {
        String view = proService.findSoftDecoration(model, session, param);
        return view;
    }

    //拉伊香薰页面
    @GetMapping("/perfume")
    public String perfume(Model model, HttpSession session, String param) {
        String view = proService.findPerfume(model, session, param);
        return view;
    }
}
